
package com.trydofor.id.byta;


/**
 * a9 packet head
 * 
 * <pre>
 * the bits layout
 * 1) long 8-byte = 64-bit
 * ----.----1----.----2----.----3----.----4----.----5----.----6----
 * 0101011010100000101110101101000011001010111111100000110110101101-FIXEDBIT long(53-bit,value=1386)
 * 010101101010....................................................-YI:63&64,HEX:56A
 * ............0000101110101101000011001010111111100000110110101101-HEX:.BAD.CAFE.DAD
 * 2) int  4-byte = 32-bit
 * 00000000000000000000000000000000-AUTHCODE int(32-bit,size=4G)
 * 3) long 8-byte = 64-bit
 * 0...............................................................-FIXED
 * .000000000000000000000000000000000000000000000000000000000000000-DEALCODE long(63-bit,size=2T)
 * 4) int  4-byte = 32-bit
 * 00000000000000000000000000000000-BODYTYPE int(32-bit,size=4G)
 * 5) int  4-byte = 32-bit
 * 0...............................-FIXED
 * .0000000000000000000000000000000-BODYSIZE int(31-bit,size=2G)
 * 
 * - FIXEDBIT - the fixed token of head.
 * - AUTHCODE - the auth code of session
 * - DEALCODE - the deal code, SHOULD be millisecond or nanosecond.
 * - BODYTYPE - the body type.
 * - BODYSIZE - the body byte size.
 * </pre>
 * 
 * @author : Shi Rongjiu (www.trydofor.com)
 */
public final class Head {
    
    /**
     * the head byte size.
     */
    public static final int    BYTE_SIZE      = 8 + 4 + 8 + 4 + 4;
    
    /**
     * the fixed token.
     */
    public static final long   FIXED_TOKEN    = 0X56A0BAD0CAFE0DADL;
    
    // -------------------------
    private final int          authCode;
    private final long         dealCode;
    private transient int      bodyType;
    private transient int      bodySize;
    
    /**
     * constructor.
     * 
     * @param authCode the auth code
     * @param dealcode the deal code
     * 
     * @throws IllegalArgumentException if worker out of range.
     */
    public Head(int authCode, long dealcode) {
        
        this.dealCode = dealcode;
        this.authCode = authCode;
        this.bodyType = 0;
        this.bodySize = 0;
    }
    
    /**
     * get the authCode
     */
    public int getAuthCode() {
        return authCode;
    }
    
    /**
     * @return the dealCode
     */
    public long getDealCode() {
        return dealCode;
    }
    
    /**
     * @return the bodyType
     */
    public int getBodyType() {
        return bodyType;
    }
    
    /**
     * @param bodyType the bodyType to set
     */
    public void setBodyType(int bodyType) {
        this.bodyType = bodyType;
    }
    
    /**
     * @return the bodySize
     */
    public int getBodySize() {
        return bodySize;
    }
    
    /**
     * @param bodySize the bodySize to set
     */
    public void setBodySize(int bodySize) {
        this.bodySize = bodySize;
    }
    
    @Override
    public String toString() {
        return "Head[authCode=" + authCode + ", dealCode=" + dealCode + ", bodyType=" + bodyType
               + ", bodySize=" + bodySize + "]";
    }
}
